#ifndef __MAILER_H
#define __MAILER_H

#include <map>
#include <stdlib.h>
#include <bitset>
#include <vector>
#include "Node.h"
#include "MessengerBounded.h"

class Shell;

class Mailer: public MessengerBounded {
private:
	map<int, Node *> * nodes;
	Shell * shell;
	pthread_t thread;
	int bufferSize;

	void handleSysMsg(Message * msg);
	void handleRTMsg(Message * msg);
	void handleMsg(Message * msg);

	void RRschedule();
	void MLQSchedule();
	void OurSchedule();

	void calcQuantaUsage(int realQuanta,int nodeQuantaLeft);

	bool stabilaize;
public:
	enum { RR = 0, MLQ=1, OUR=2 };
	Mailer(map<int, Node *> * data, int size, Shell * shell);

	~Mailer();
	bool active;
	int contextSwitches;
	int quantaUsage;
	int schedule;
	int algQuanta;
	pthread_t getThread();
	map<int, Node *> * getNodes();
	void start();
	//void* runt(void* args);
	void run();
	void setStabilize(bool stab);
	bool getStabilize();

};
#endif
